import java.io.*;
import java.util.*;

public class Staff {
	private int StaffID;
	private String StaffName;
	private String StaffPosition;
	public static String filename = "Movies_data.txt" ;
	
	public Staff(int staffid, String staffname, String staffposition){
		StaffID = staffid;
		StaffName = staffname;
		StaffPosition = staffposition;
	}
	
	/*
	 * changePrice
	 * input: movieID - the movie whose price needed to be changed
	 * 		  movieName - 	the movie whose price needed to be changed
	 * 	      movieShowtime - the movie whose showtime matches the one needed to be changed
	 * 		  newPrice - the price to be updated for this movie
	 * 
	*/
	public static void changePrice(int movieID, String movieName, String movieShowtime, int newPrice){
		
		try{
			ArrayList movies = TextDB.readMovies(filename);
			PrintWriter writer = new PrintWriter(filename);
			writer.print("");
			writer.close();
			for(int i = 0;i<movies.size();i++){
				Movie movie = (Movie)movies.get(i);
				if (movie.getID()==movieID && movie.getName().equals(movieName) && movie.getDate().equals(movieShowtime)){
					movies.remove(i);
					Movie updatedMovie = new Movie(movie.getID(),movie.getName(),movie.getDate(),movie.getType(),movie.getRating(),movie.getStatus(),movie.getDuration(),newPrice);
					movies.add(updatedMovie);
				}
			}
			TextDB.saveMovies(filename, movies);
		}catch(IOException e){
			System.out.println("IOException > " + e.getMessage());
		}
		
	}
	
	/* delete(int movieID, String movieName)
	 * 
	 * movieID and movieName are variables that indicate which movie to delete
	 * 
	 * */
	
	public void delete(int movieID, String movieName){
		
		try{
			ArrayList movies = TextDB.readMovies(filename);
			PrintWriter writer = new PrintWriter(filename);
			writer.print("");
			writer.close();
			for(int i = 0;i<movies.size();i++){
				Movie movie = (Movie)movies.get(i);
				if (movie.getID()==movieID && movie.getName().equals(movieName)){
					movies.remove(i);
					System.out.println("The movie '"+movie.getName()+"' is removed successfully.");
				}
			}
			TextDB.saveMovies("Movies_data.txt", movies);
			
			
		}catch(IOException e){
			System.out.println("IOException > " + e.getMessage());
		}

	}
	
	

}
